package com.shawn.server.util;

import com.shawn.model.mongo.Movement;
import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GeodeticCurve;
import org.gavaghan.geodesy.GlobalCoordinates;

/**
 * 计算距离
 *
 * @author lenovo
 * @date 2022/11/01
 */
public class CalculateDistance {


    /*private String longitude; //经度
    private String latitude; //纬度*/

    public static String getDistance(Double longitude1,Double latitude1,String longitude2,String latitude2){
        //构造对象
        GlobalCoordinates start = new GlobalCoordinates( latitude1,longitude1);
        GlobalCoordinates end = new GlobalCoordinates(Double.parseDouble(latitude2),Double.parseDouble(longitude2));
        //创建GeodeticCalculator，调用计算方法，传入坐标系、经纬度用于计算距离
        GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(Ellipsoid.Sphere,start,end);
        double distance = geoCurve.getEllipsoidalDistance();
        if (distance<=1000){
            return (int)distance+"米";
        }else{
            distance=distance/1000;
            return (int)distance+"公里";
        }
    }
}